package com.sunny.blockqueue;

import java.util.concurrent.LinkedBlockingQueue;

public class Consumer implements Runnable {

    private String name;
    private LinkedBlockingQueue<Integer> queue;

    public Consumer(String name, LinkedBlockingQueue<Integer> queue) {
        this.name = name;
        this.queue = queue;
    }

    @Override
    public void run() {

        while (true){

            try {
                int product = queue.take();
                System.out.println(name+"消费任务："+product+"。队列长度为："+queue.size());
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }
}
